package hdfs_pro;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class WriteFile {
    public static void main(String[] args) {
        try {
              Configuration conf = new Configuration();
              FileSystem fs = FileSystem.get(conf);
              String filePath = args[0];
              Path srcPath = new Path(filePath);
              FSDataOutputStream os = fs.create(srcPath,true,1024,(short)1,(long)(1<<26));
              String str = "Hello, this is a sentence that should be written into the file.\n";
              os.write(str.getBytes());
              os.flush();
              os.close();
            
              os = fs.append(srcPath);
              str = "Hello, this is another sentence that should be written into the file.\n";
              os.write(str.getBytes());
              os.flush();
              os.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
}